package com.xjj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjj.entity.Klass;
import com.xjj.entity.School;
import com.xjj.mapper.KlassMapper;
import com.xjj.service.KlassService;
import com.xjj.service.SchoolService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sxy
 * @version 1.0
 * @date 2022/10/20 15:11
 */
@Service
public class KlassServiceImpl extends ServiceImpl<KlassMapper, Klass> implements KlassService {
    @Resource
    private KlassMapper klassMapper;
    @Resource
    private SchoolService schoolService;
    @Override
    public void addJobNumById(Klass klass) {
        klassMapper.addJobNumById(klass);
    }

    @Override
    public void subJobNumBuId(int num, int id) {
        System.out.println(num+"..."+id);
        Klass klassById = klassMapper.getKlassById(id);
        num = klassById.getJobNum()-num;
        klassMapper.subJobNumBuId(num,id);
    }

    @Override
    public Klass getKlassById(int id) {
        return klassMapper.getKlassById(id);
    }

    @Override
    public void updateVerifyById(String klassVerify, int id) {
        klassMapper.updateVerifyById(klassVerify,id);
    }

    @Override
    @Transactional
    public List<Klass> getKlassByManagerId(int id) {
        List<Klass> klasses = klassMapper.getKlassByManagerId(id);
        for (Klass klass : klasses) {
            School school = schoolService.getSchoolByKlassId(klass.getSchoolId());
            klass.setSchool(school);
        }
        return klasses;
    }

    @Override
    public Klass isExist(String classname) {
        Klass klass = klassMapper.getKlassByName(classname);
        return klass;
    }

    @Override
    public Klass getKlassByMasterId(int id) {
        Klass klass = klassMapper.getKlassByMasterId(id);
        return klass;
    }


}
